using System;
using System.Collections;
using System.Globalization;
using System.Text;
using Altova.Types;

namespace Altova
{
	public class CoreTypes
	{
		public class NumberParts
		{
			public readonly char Sign;

			public readonly string Mantissa;

			public readonly string Exponent;

			public readonly bool Valid;

			public NumberParts(string input)
			{
				input = input.Trim();
				if (input.StartsWith("+") || input.StartsWith("-"))
				{
					Sign = input[0];
					input = input.Substring(1);
				}
				else
				{
					Sign = '+';
				}
				int num = input.IndexOfAny(new char[2] { 'e', 'E' });
				if (num < 0)
				{
					Mantissa = input;
					Exponent = "";
				}
				else
				{
					Mantissa = input.Substring(0, num);
					Exponent = input.Substring(num + 1);
				}
				if (Mantissa.StartsWith("."))
				{
					Mantissa = "0" + Mantissa;
				}
				if (Mantissa.EndsWith("."))
				{
					Mantissa += "0";
				}
				if (Mantissa.Length == 0)
				{
					Mantissa = "0";
				}
				if (Exponent.EndsWith("+") || Exponent.EndsWith("-"))
				{
					Exponent += "0";
				}
			}

			public override string ToString()
			{
				if (Exponent.Length > 0)
				{
					return Sign + Mantissa + "E" + Exponent;
				}
				return Sign + Mantissa;
			}

			public double ToDouble()
			{
				return double.Parse(ToString(), CultureInfo.InvariantCulture);
			}

			public decimal ToDecimal()
			{
				return decimal.Parse(Sign + Mantissa, CultureInfo.InvariantCulture);
			}

			public long ToLong()
			{
				int num = Mantissa.IndexOf('.');
				if (num >= 0)
				{
					return long.Parse(Sign + Mantissa.Substring(0, num));
				}
				return long.Parse(Sign + Mantissa);
			}

			public ulong ToULong()
			{
				int num = Mantissa.IndexOf('.');
				if (num >= 0)
				{
					return ulong.Parse(Sign + Mantissa.Substring(0, num));
				}
				return ulong.Parse(Sign + Mantissa);
			}

			public bool IsNumber()
			{
				try
				{
					double.Parse(ToString());
					return true;
				}
				catch (Exception)
				{
					return false;
				}
			}
		}

		private static bool IsSchemaSign(char c)
		{
			if (c != '+')
			{
				return c == '-';
			}
			return true;
		}

		private static bool IsSchemaDigit(char c)
		{
			if (c >= '0')
			{
				return c <= '9';
			}
			return false;
		}

		private static bool IsSchemaRadix(char c)
		{
			return c == '.';
		}

		private static bool IsSchemaExponent(char c)
		{
			if (c != 'e')
			{
				return c == 'E';
			}
			return true;
		}

		private static int PrepareNumber(StringBuilder buffer, string input)
		{
			int[,] array = new int[9, 5]
			{
				{ 0, 0, 1, 2, 2 },
				{ 2, 0, 1, 2, 2 },
				{ 2, 0, 0, 0, 2 },
				{ 2, 0, 2, 2, 2 },
				{ 2, 0, 2, 0, 2 },
				{ 2, 0, 2, 1, 2 },
				{ 0, 0, 2, 2, 2 },
				{ 2, 0, 2, 2, 2 },
				{ 2, 0, 2, 2, 2 }
			};
			int[,] array2 = new int[9, 5]
			{
				{ 1, 2, 3, 9, 9 },
				{ 9, 2, 3, 9, 9 },
				{ 9, 2, 5, 6, 9 },
				{ 9, 4, 9, 9, 9 },
				{ 9, 4, 9, 6, 9 },
				{ 9, 4, 9, 6, 9 },
				{ 7, 8, 9, 9, 9 },
				{ 9, 8, 9, 9, 9 },
				{ 9, 8, 9, 9, 9 }
			};
			int num = 0;
			foreach (char c in input)
			{
				int num2 = (IsSchemaDigit(c) ? 1 : ((!IsSchemaSign(c)) ? (IsSchemaRadix(c) ? 2 : ((!IsSchemaExponent(c)) ? 4 : 3)) : 0));
				switch (array[num, num2])
				{
				case 0:
					buffer.Append(c);
					break;
				case 1:
					buffer.Append('0');
					buffer.Append(c);
					break;
				case 2:
					return 0;
				}
				num = array2[num, num2];
			}
			switch (num)
			{
			case 0:
			case 1:
			case 3:
			case 6:
			case 7:
				return 0;
			case 2:
				return 1;
			case 4:
				return 2;
			case 5:
				buffer.Append('0');
				return 2;
			case 8:
				return 3;
			default:
				return 0;
			}
		}

		public static IEnumerable castToEnumerable(object o)
		{
			return (IEnumerable)o;
		}

		public static int CastToInt(int i)
		{
			return i;
		}

		public static int CastToInt(uint i)
		{
			if (i > int.MaxValue)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for int.", i));
			}
			return (int)i;
		}

		public static int CastToInt(double d)
		{
			if (d < -2147483648.0 || d > 2147483647.0)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for int.", d));
			}
			return (int)d;
		}

		public static int CastToInt(string s)
		{
			if (s == null)
			{
				return 0;
			}
			s = s.Trim();
			switch (s)
			{
			case "NaN":
			case "INF":
			case "-INF":
				throw new OverflowException("'" + s + "' is out of range for int.");
			default:
			{
				StringBuilder buffer = new StringBuilder();
				switch (PrepareNumber(buffer, s))
				{
				case 1:
					return int.Parse(s, CultureInfo.InvariantCulture);
				case 2:
					return (int)decimal.Parse(s, CultureInfo.InvariantCulture);
				case 3:
					return checked((int)double.Parse(s, CultureInfo.InvariantCulture));
				default:
					throw new ArgumentException("'" + s + "' cannot be parsed as int.");
				}
			}
			}
		}

		public static int CastToInt(long i)
		{
			if (i < int.MinValue || i > int.MaxValue)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for int.", i));
			}
			return (int)i;
		}

		public static int CastToInt(ulong i)
		{
			if (i > int.MaxValue)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for int.", i));
			}
			return (int)i;
		}

		public static int CastToInt(decimal d)
		{
			return (int)d;
		}

		public static uint CastToUInt(int i)
		{
			if (i < 0)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for uint.", i));
			}
			return (uint)i;
		}

		public static uint CastToUInt(uint i)
		{
			return i;
		}

		public static uint CastToUInt(double d)
		{
			if (d < 0.0 || d > 4294967295.0)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for uint.", d));
			}
			return (uint)d;
		}

		public static uint CastToUInt(string s)
		{
			if (s == null)
			{
				return 0u;
			}
			s = s.Trim();
			switch (s)
			{
			case "NaN":
			case "INF":
			case "-INF":
				throw new OverflowException("'" + s + "' is out of range for int.");
			default:
			{
				StringBuilder buffer = new StringBuilder();
				switch (PrepareNumber(buffer, s))
				{
				case 1:
					return uint.Parse(s, CultureInfo.InvariantCulture);
				case 2:
					return (uint)decimal.Parse(s, CultureInfo.InvariantCulture);
				case 3:
					return checked((uint)double.Parse(s, CultureInfo.InvariantCulture));
				default:
					throw new ArgumentException("'" + s + "' cannot be parsed as int.");
				}
			}
			}
		}

		public static uint CastToUInt(long i)
		{
			if (i < 0 || i > uint.MaxValue)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for uint.", i));
			}
			return (uint)i;
		}

		public static uint CastToUInt(ulong i)
		{
			if (i > uint.MaxValue)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for uint.", i));
			}
			return (uint)i;
		}

		public static uint CastToUInt(decimal d)
		{
			return (uint)d;
		}

		public static long CastToInt64(int i)
		{
			return i;
		}

		public static long CastToInt64(uint i)
		{
			return i;
		}

		public static long CastToInt64(double d)
		{
			if (d < -9.223372036854776E+18 || d > 9.223372036854776E+18)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for long.", d));
			}
			return (long)d;
		}

		public static long CastToInt64(string s)
		{
			if (s == null)
			{
				return 0L;
			}
			s = s.Trim();
			switch (s)
			{
			case "NaN":
			case "INF":
			case "-INF":
				throw new OverflowException("'" + s + "' is out of range for int.");
			default:
			{
				StringBuilder buffer = new StringBuilder();
				switch (PrepareNumber(buffer, s))
				{
				case 1:
					return long.Parse(s, CultureInfo.InvariantCulture);
				case 2:
					return (long)decimal.Parse(s, CultureInfo.InvariantCulture);
				case 3:
					return checked((long)double.Parse(s, CultureInfo.InvariantCulture));
				default:
					throw new ArgumentException("'" + s + "' cannot be parsed as int.");
				}
			}
			}
		}

		public static long CastToInt64(long i)
		{
			return i;
		}

		public static long CastToInt64(ulong i)
		{
			if (i > long.MaxValue)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for long.", i));
			}
			return (long)i;
		}

		public static long CastToInt64(decimal d)
		{
			return (long)d;
		}

		public static ulong CastToUInt64(int i)
		{
			if (i < 0)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for ulong.", i));
			}
			return (ulong)i;
		}

		public static ulong CastToUInt64(uint i)
		{
			return i;
		}

		public static ulong CastToUInt64(double d)
		{
			if (d < 0.0 || d > 1.8446744073709552E+19)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for ulong.", d));
			}
			return (ulong)d;
		}

		public static ulong CastToUInt64(string s)
		{
			if (s == null)
			{
				return 0uL;
			}
			s = s.Trim();
			switch (s)
			{
			case "NaN":
			case "INF":
			case "-INF":
				throw new OverflowException("'" + s + "' is out of range for int.");
			default:
			{
				StringBuilder buffer = new StringBuilder();
				switch (PrepareNumber(buffer, s))
				{
				case 1:
					return ulong.Parse(s, CultureInfo.InvariantCulture);
				case 2:
					return (ulong)decimal.Parse(s, CultureInfo.InvariantCulture);
				case 3:
					return checked((ulong)double.Parse(s, CultureInfo.InvariantCulture));
				default:
					throw new ArgumentException("'" + s + "' cannot be parsed as int.");
				}
			}
			}
		}

		public static ulong CastToUInt64(long i)
		{
			if (i < 0)
			{
				throw new OverflowException(string.Format("Numeric value overflow: {0} out of range for ulong.", i));
			}
			return (ulong)i;
		}

		public static ulong CastToUInt64(ulong i)
		{
			return i;
		}

		public static ulong CastToUInt64(decimal d)
		{
			return (ulong)d;
		}

		public static double CastToDouble(bool b)
		{
			return b ? 1 : 0;
		}

		public static double CastToDouble(int i)
		{
			return i;
		}

		public static double CastToDouble(uint i)
		{
			return i;
		}

		public static double CastToDouble(long i)
		{
			return i;
		}

		public static double CastToDouble(ulong i)
		{
			return i;
		}

		public static double CastToDouble(double d)
		{
			return d;
		}

		public static double CastToDouble(string s)
		{
			if (s == null)
			{
				return 0.0;
			}
			s = s.Trim();
			switch (s)
			{
			case "NaN":
				return double.NaN;
			case "INF":
				return double.PositiveInfinity;
			case "-INF":
				return double.NegativeInfinity;
			default:
			{
				StringBuilder buffer = new StringBuilder();
				switch (PrepareNumber(buffer, s))
				{
				case 1:
				case 2:
				case 3:
					return double.Parse(s, CultureInfo.InvariantCulture);
				default:
					throw new ArgumentException("'" + s + "' cannot be parsed as int.");
				}
			}
			}
		}

		public static double CastToDouble(decimal d)
		{
			return (double)d;
		}

		public static decimal CastToDecimal(bool b)
		{
			return b ? 1 : 0;
		}

		public static decimal CastToDecimal(int i)
		{
			return i;
		}

		public static decimal CastToDecimal(uint i)
		{
			return i;
		}

		public static decimal CastToDecimal(long i)
		{
			return i;
		}

		public static decimal CastToDecimal(ulong i)
		{
			return i;
		}

		public static decimal CastToDecimal(double i)
		{
			return (decimal)i;
		}

		public static decimal CastToDecimal(decimal i)
		{
			return i;
		}

		public static decimal CastToDecimal(string s)
		{
			if (s == null)
			{
				return 0m;
			}
			s = s.Trim();
			switch (s)
			{
			case "NaN":
			case "INF":
			case "-INF":
				throw new OverflowException("'" + s + "' is out of range for int.");
			default:
			{
				StringBuilder buffer = new StringBuilder();
				switch (PrepareNumber(buffer, s))
				{
				case 1:
				case 2:
					return decimal.Parse(s, CultureInfo.InvariantCulture);
				case 3:
					return (decimal)double.Parse(s, CultureInfo.InvariantCulture);
				default:
					throw new ArgumentException("'" + s + "' cannot be parsed as int.");
				}
			}
			}
		}

		public static string CastToString(int i)
		{
			return i.ToString(NumberFormatInfo.InvariantInfo);
		}

		public static string CastToString(uint i)
		{
			return i.ToString(NumberFormatInfo.InvariantInfo);
		}

		public static string CastToString(long i)
		{
			return i.ToString(NumberFormatInfo.InvariantInfo);
		}

		public static string CastToString(ulong i)
		{
			return i.ToString(NumberFormatInfo.InvariantInfo);
		}

		public static string CastToString(double d)
		{
			return d.ToString(NumberFormatInfo.InvariantInfo);
		}

		public static string CastToString(string s)
		{
			return s;
		}

		public static string CastToString(bool b)
		{
			if (b)
			{
				return "true";
			}
			return "false";
		}

		public static string CastToString(Altova.Types.DateTime dt)
		{
			return dt.ToString();
		}

		public static string CastToString(Altova.Types.DateTime dt, DateTimeFormat format)
		{
			return dt.ToString(format);
		}

		public static string CastToString(object o_which_is_a_dt, DateTimeFormat format)
		{
			return ((Altova.Types.DateTime)o_which_is_a_dt).ToString(format);
		}

		public static string CastToString(Duration dur)
		{
			return dur.ToString();
		}

		public static string CastToString(byte[] val)
		{
			return Convert.ToBase64String(val);
		}

		public static string CastToString(decimal d)
		{
			string text = d.ToString(NumberFormatInfo.InvariantInfo);
			int num = text.LastIndexOf('.');
			if (num >= 0)
			{
				if (text.Length > num)
				{
					text = text.TrimEnd('0');
				}
				if (text.Length == num + 1)
				{
					text = text.Substring(0, num);
				}
			}
			if (text.Length == 0)
			{
				text = "0";
			}
			return text;
		}

		public static QName CastToQName(object o)
		{
			if (o is string)
			{
				return CastToQName((string)o);
			}
			if (o is QName)
			{
				return CastToQName((QName)o);
			}
			return null;
		}

		public static string CastToString(QName qn)
		{
			return qn.ToString();
		}

		public static QName CastToQName(string s)
		{
			return new QName(s);
		}

		public static QName CastToQName(QName qn)
		{
			return qn;
		}

		public static Altova.Types.DateTime CastToDateTime(string s)
		{
			if (s == null)
			{
				throw new NullReferenceException();
			}
			if (s == "")
			{
				throw new StringParseException("Cast to DateTime failed.");
			}
			return Altova.Types.DateTime.Parse(s);
		}

		public static Duration CastToDuration(string s)
		{
			if (s == null)
			{
				throw new NullReferenceException();
			}
			if (s == "")
			{
				throw new StringParseException("Cast to Duration failed.");
			}
			return Duration.Parse(s);
		}

		public static Altova.Types.DateTime CastToDateTime(Altova.Types.DateTime s)
		{
			return s;
		}

		public static Altova.Types.DateTime CastToDateTime(Altova.Types.DateTime s, DateTimeFormat format)
		{
			return s;
		}

		public static Duration CastToDuration(Duration s)
		{
			return s;
		}

		public static bool CastToBool(bool b)
		{
			return b;
		}

		public static bool CastToBool(int i)
		{
			return i != 0;
		}

		public static bool CastToBool(uint i)
		{
			return i != 0;
		}

		public static bool CastToBool(long i)
		{
			return i != 0;
		}

		public static bool CastToBool(ulong i)
		{
			return i != 0;
		}

		public static bool CastToBool(double d)
		{
			return d != 0.0;
		}

		public static bool CastToBool(string v)
		{
			switch (v.Trim())
			{
			case "true":
			case "1":
				return true;
			case "false":
			case "0":
				return false;
			default:
				throw new ArgumentException("'" + v + "' cannot be parsed as boolean.");
			}
		}

		public static bool CastToBool(decimal d)
		{
			return d != 0m;
		}

		public static bool Exists(object o)
		{
			return o != null;
		}

		public static int CastToInt(object v)
		{
			if (!Exists(v))
			{
				throw new NullReferenceException();
			}
			if (v is string)
			{
				return CastToInt((string)v);
			}
			return Convert.ToInt32(v, CultureInfo.InvariantCulture);
		}

		public static uint CastToUInt(object v)
		{
			if (!Exists(v))
			{
				throw new NullReferenceException();
			}
			if (v is string)
			{
				return CastToUInt((string)v);
			}
			return Convert.ToUInt32(v, CultureInfo.InvariantCulture);
		}

		public static string CastToString(object v)
		{
			if (!Exists(v))
			{
				throw new NullReferenceException();
			}
			if (v is Altova.Types.DateTime)
			{
				return CastToString(CastToDateTime(v));
			}
			if (v is bool)
			{
				return CastToString(CastToBool(v));
			}
			if (v is decimal)
			{
				return CastToString(CastToDecimal(v));
			}
			return Convert.ToString(v, CultureInfo.InvariantCulture);
		}

		public static double CastToDouble(object v)
		{
			if (!Exists(v))
			{
				throw new NullReferenceException();
			}
			if (v is string)
			{
				return CastToDouble((string)v);
			}
			return Convert.ToDouble(v, CultureInfo.InvariantCulture);
		}

		public static decimal CastToDecimal(object v)
		{
			if (!Exists(v))
			{
				throw new NullReferenceException();
			}
			if (v is string)
			{
				return CastToDecimal((string)v);
			}
			return Convert.ToDecimal(v, CultureInfo.InvariantCulture);
		}

		public static long CastToInt64(object v)
		{
			if (!Exists(v))
			{
				throw new NullReferenceException();
			}
			if (v is string)
			{
				return CastToInt64((string)v);
			}
			return Convert.ToInt64(v, CultureInfo.InvariantCulture);
		}

		public static ulong CastToUInt64(object v)
		{
			if (!Exists(v))
			{
				throw new NullReferenceException();
			}
			if (v is string)
			{
				return CastToUInt64((string)v);
			}
			return Convert.ToUInt64(v, CultureInfo.InvariantCulture);
		}

		public static bool CastToBool(Altova.Types.DateTime v, DateTimeFormat format)
		{
			return v != null;
		}

		public static bool CastToBool(object v)
		{
			if (!Exists(v))
			{
				throw new NullReferenceException();
			}
			if (v is string)
			{
				return CastToBool((string)v);
			}
			return Convert.ToBoolean(v, CultureInfo.InvariantCulture);
		}

		public static Altova.Types.DateTime CastToDateTime(object v)
		{
			if (!Exists(v))
			{
				throw new NullReferenceException();
			}
			if (v is string)
			{
				return CastToDateTime((string)v);
			}
			return (Altova.Types.DateTime)v;
		}

		public static Altova.Types.DateTime CastToDateTime(object v, DateTimeFormat format)
		{
			if (!Exists(v))
			{
				throw new NullReferenceException();
			}
			if (v is string)
			{
				return CastToDateTime((string)v, format);
			}
			return (Altova.Types.DateTime)v;
		}

		public static Duration CastToDuration(object v)
		{
			if (!Exists(v))
			{
				throw new NullReferenceException();
			}
			if (v is string)
			{
				return CastToDuration((string)v);
			}
			return (Duration)v;
		}

		public static byte[] CastToBinary(object v)
		{
			if (!Exists(v))
			{
				throw new NullReferenceException();
			}
			if (v is string)
			{
				CastToBinary((string)v);
			}
			return (byte[])v;
		}

		public static byte[] CastToBinary(string s)
		{
			UnicodeEncoding unicodeEncoding = new UnicodeEncoding();
			return unicodeEncoding.GetBytes(s);
		}

		public static byte[] CastToBinary(byte[] b)
		{
			return b;
		}

		public static string FormatNumber(uint value, uint minDigits)
		{
			return value.ToString("D" + minDigits, NumberFormatInfo.InvariantInfo);
		}

		public static string FormatNumber(int value, uint minDigits)
		{
			return value.ToString("D" + minDigits, NumberFormatInfo.InvariantInfo);
		}

		public static string FormatTimezone(int value)
		{
			string text = "";
			if (value == 0)
			{
				return text + 'Z';
			}
			if (value < 0)
			{
				text += '-';
				value = -value;
			}
			else
			{
				text += '+';
			}
			text += FormatNumber((uint)value / 60u, 2u);
			text += ':';
			return text + FormatNumber((uint)value % 60u, 2u);
		}

		public static string FormatFraction(uint value, uint precision)
		{
			string text = "";
			if (value != 0)
			{
				text += '.';
				text += FormatNumber(value, precision);
				int num = text.Length;
				while (text[num - 1] == '0')
				{
					num--;
				}
				text = text.Remove(num, text.Length - num);
			}
			return text;
		}

		public static string DecimalToString(decimal v)
		{
			return CastToString(v);
		}

		public static decimal ParseDecimal(string v)
		{
			return CastToDecimal(v);
		}

		public static string DoubleToString(double v)
		{
			return CastToString(v);
		}

		public static double ParseDouble(string v)
		{
			return CastToDouble(v);
		}

		public static Altova.Types.DateTime CastToDateTime(string v, DateTimeFormat format)
		{
			return Altova.Types.DateTime.Parse(v, format);
		}

		public static string DateTimeToString(Altova.Types.DateTime v)
		{
			return CastToString(v, DateTimeFormat.W3_dateTime);
		}

		public static Altova.Types.DateTime ParseDateTime(string v)
		{
			return CastToDateTime(v, DateTimeFormat.W3_dateTime);
		}

		public static string DateToString(Altova.Types.DateTime v)
		{
			return CastToString(v, DateTimeFormat.W3_date);
		}

		public static Altova.Types.DateTime ParseDate(string v)
		{
			return CastToDateTime(v, DateTimeFormat.W3_date);
		}

		public static string TimeToString(Altova.Types.DateTime v)
		{
			return CastToString(v, DateTimeFormat.W3_time);
		}

		public static Altova.Types.DateTime ParseTime(string v)
		{
			return CastToDateTime(v, DateTimeFormat.W3_time);
		}

		public static string GYearToString(Altova.Types.DateTime v)
		{
			return CastToString(v, DateTimeFormat.W3_gYear);
		}

		public static Altova.Types.DateTime ParseGYear(string v)
		{
			return CastToDateTime(v, DateTimeFormat.W3_gYear);
		}

		public static decimal GYearToInteger(Altova.Types.DateTime v)
		{
			return v.Value.Year;
		}

		public static Altova.Types.DateTime IntegerToGYear(decimal v)
		{
			return new Altova.Types.DateTime((int)v, 1, 1);
		}

		public static string GMonthToString(Altova.Types.DateTime v)
		{
			return CastToString(v, DateTimeFormat.W3_gMonth);
		}

		public static Altova.Types.DateTime ParseGMonth(string v)
		{
			return CastToDateTime(v, DateTimeFormat.W3_gMonth);
		}

		public static string GDayToString(Altova.Types.DateTime v)
		{
			return CastToString(v, DateTimeFormat.W3_gDay);
		}

		public static Altova.Types.DateTime ParseGDay(string v)
		{
			return CastToDateTime(v, DateTimeFormat.W3_gDay);
		}

		public static string GYearMonthToString(Altova.Types.DateTime v)
		{
			return CastToString(v, DateTimeFormat.W3_gYearMonth);
		}

		public static Altova.Types.DateTime ParseGYearMonth(string v)
		{
			return CastToDateTime(v, DateTimeFormat.W3_gYearMonth);
		}

		public static string GMonthDayToString(Altova.Types.DateTime v)
		{
			return CastToString(v, DateTimeFormat.W3_gMonthDay);
		}

		public static Altova.Types.DateTime ParseGMonthDay(string v)
		{
			return CastToDateTime(v, DateTimeFormat.W3_gMonthDay);
		}

		public static string DurationToString(Duration v)
		{
			return CastToString(v);
		}

		public static Duration ParseDuration(string v)
		{
			return CastToDuration(v);
		}

		public static string BinaryToBase64String(byte[] v)
		{
			return Convert.ToBase64String(v, 0, v.Length);
		}

		public static byte[] ParseBase64Binary(string v)
		{
			return Convert.FromBase64String(v);
		}

		public static string BinaryToHexString(byte[] v)
		{
			return HexBinary.decode(v);
		}

		public static byte[] ParseHexBinary(string v)
		{
			return HexBinary.encode(v);
		}

		public static string BooleanToString(bool v)
		{
			if (!v)
			{
				return "false";
			}
			return "true";
		}

		public static int BooleanToInt(bool v)
		{
			if (!v)
			{
				return 0;
			}
			return 1;
		}

		public static bool ParseBoolean(string v)
		{
			return CastToBool(v);
		}

		public static string QNameToString(QName v)
		{
			return v.ToString();
		}

		public static QName StringToQName(string s)
		{
			return CastToQName(s);
		}

		public static bool StringToBoolean(string v)
		{
			return CastToBool(v);
		}

		public static decimal LongToDecimal(long v)
		{
			return v;
		}

		public static decimal ULongToDecimal(ulong v)
		{
			return v;
		}

		public static long IntToLong(int v)
		{
			return v;
		}

		public static decimal IntToDecimal(int v)
		{
			return v;
		}

		public static ulong DecimalToULong(decimal v)
		{
			return (ulong)v;
		}

		public static int LongToInt(long v)
		{
			return (int)v;
		}

		public static long DecimalToLong(decimal v)
		{
			return (long)v;
		}

		public static int DecimalToInt(decimal v)
		{
			return (int)v;
		}

		public static decimal DecimalToInteger(decimal v)
		{
			return decimal.Truncate(v);
		}

		public static long ParseLong(string v)
		{
			return CastToInt64(v);
		}

		public static ulong ParseULong(string v)
		{
			return CastToUInt64(v);
		}

		public static int ParseInt(string v)
		{
			return CastToInt(v);
		}

		public static decimal BooleanToDecimal(bool v)
		{
			if (v)
			{
				return 1.0m;
			}
			return 0.0m;
		}

		public static double BooleanToDouble(bool v)
		{
			if (!v)
			{
				return 0.0;
			}
			return 1.0;
		}

		public static bool DecimalToBoolean(decimal v)
		{
			return v != 0.0m;
		}

		public static bool DoubleToBoolean(double v)
		{
			return v != 0.0;
		}

		public static decimal DoubleToDecimal(double v)
		{
			return (decimal)v;
		}

		public static double DecimalToDouble(decimal v)
		{
			return (double)v;
		}
	}
}
